package com.elinkway.infinitemovies.async;

import android.content.Context;

import com.elinkway.infinitemovies.bean.UpLoadLocalStreamBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.UpLoadLocalStreamBeanParser;
import com.lvideo.http.bean.LVideoDataHull;

import java.util.List;

/**
 * Created by wangyemin on 2015/12/14.
 */
public class UpLoadLocalStreamTask extends MoviesHttpAsyncTask<UpLoadLocalStreamBean> {
    private List<String> allow_formats;
    private String request_format;
    private List<String> stream_list;
    private String osType;
    private String playUrl;
    private RequestResultListener<UpLoadLocalStreamBean> listener;

    public UpLoadLocalStreamTask(Context context, List<String> allow_formats, String request_format, String osType, String playUrl) {
        super(context);
        this.allow_formats = allow_formats;
        this.request_format = request_format;
        this.osType = osType;
        this.playUrl = playUrl;
    }

    public void setStream_list(List<String> stream_list) {
        this.stream_list = stream_list;
    }

    public void setListener(RequestResultListener<UpLoadLocalStreamBean> listener) {
        this.listener = listener;
    }

    @Override
    public LVideoDataHull<UpLoadLocalStreamBean> doInBackground() {
        return MoviesHttpApi.upLoadLocalStream(new UpLoadLocalStreamBeanParser(), allow_formats, request_format, stream_list, osType, playUrl);
    }

    @Override
    public void onPostExecute(int updateId, UpLoadLocalStreamBean result) {
        if (null != listener) {
            listener.onRequestSuccess(updateId, result);
        }
    }

    @Override
    public boolean onPreExecute() {
        return super.onPreExecute();
    }

    @Override
    public void netNull() {
        super.netNull();
        if (null != listener) {
            listener.onRequestFailed();
        }
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        super.netErr(updateId, errMsg);
        if (null != listener) {
            listener.onRequestFailed();
        }
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
        if (null != listener) {
            listener.onRequestFailed();
        }
    }
}
